<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
 * Micro
 * Core controller
 * @author     hypn
 */
class Core_Controller extends Controller {
	
	private $view_title;
	public $view;
	public $session;
	public $auth;
	
	public function __construct()
	{
		$this->_set_view_title('Croakd');
		$this->session	= Session::instance();
		$this->auth			= new Auth();
		parent::__construct();

    if ( !preg_match('(install)', Router::$routed_uri) && Kohana::find_file('controllers','install') )
      url::redirect('install');
	}
	
	/**
	 * Función de language
	 * @param $module
	 * @param $keycode
	 * @return string
	 */
	public function __($module, $keycode = array())	
	{
		return Kohana::lang($module, $keycode);
	}

	/**
	 * Define el titulo de la aplicacion
	 * @param $view_title
	 * @return void
	 */
	public function _set_view_title($view_title = FALSE)
	{
		if ($view_title != '') {
			$title = $view_title . ' &mdash; ' . Kohana::config('app.title'); 
		}
		else {
			$title = Kohana::config('app.title');
		}
		$this->view_title = $title;
	}
	
	/**
	 * Obtiene el titulo de la aplicacion
	 * @return string
	 */
	public function _get_view_title()
	{
		return $this->view_title;
	}
	
	/**
	 * Carga una vista del sistema
	 * @param string $view
	 * @return View object
	 */
	public function _load_view($view)
	{
		return View::factory($view)->render(TRUE);
	}

	public function _get_menu($class = FALSE)
	{
		$menu = Kohana::config('app.menu');
		$list = '<ul class="'.$class.'">';
		if (is_array($menu)) {
			foreach ($menu	as $url => $text) 
			{
				$current = ("/$url"==$_SERVER['REQUEST_URI']) ? 'class="current"' : '';
				$list .= '<li><a href="/'. $url .'" '. $current .'>'.$text.'</a></li>';			
			}
		}
		$list .= '</ul>';
		return $list;
	}
}
